import { defineStore } from "pinia";
import { useAppStore } from "./app";
export const useUserStore = defineStore({
  id: "user", // id必填，且需要唯一
  state: () => {
    return {
      name: "张三",
      age: "18",
      appKey: "app",
    };
  },
  actions: {
    updateName(name) {
      let str = this.addAge(name);
      this.name = str;
      const appStore = useAppStore();
      appStore.setData(123);
    },
    addAge(name) {
      return name + " " + 29;
    },
  },
  getters: {
    fullName: (state) => {
      return state.name + "丰";
    },
  },
  persist: {
    enabled: true,
    strategies: [
      {
        key: "my_user",
        storage: localStorage,
        paths: ["name",'appKey'],
      },
    ],
  },
});
